package com.novel.authorization.vip;

import com.alibaba.ttl.TransmittableThreadLocal;
import lombok.experimental.UtilityClass;

/**
 * VipContext
 *
 * @author 樊温军
 * @date 2025/3/25 下午2:20
 */
@UtilityClass
public class VipContextHolder {

    private final ThreadLocal<Integer> THREAD_LOCAL_VIP = new TransmittableThreadLocal<>();


    /**
     * TTL 设置Vip等级
     *
     * @param vip Vip等级
     */
    public void setVip(Integer vip) {
        if (null == vip) {
            vip = 0;
        }
        THREAD_LOCAL_VIP.set(vip);
    }

    /**
     * 获取TTL中的Vip等级
     *
     * @return String
     */
    public Integer getVip() {
        return THREAD_LOCAL_VIP.get();
    }

    public void clear() {
        THREAD_LOCAL_VIP.remove();
    }
}
